// pages/user/index.js
Page({
  data:{
    userinfo:{},
    collectNums:0,
    nickName: "微信账号登录",
    avatarUrl: "./user-unlogin.png",
  },
  onLoad: function () {

    var that = this;
    var nickName = that.data.nickName;
    var avatarUrl = that.data.avatarUrl;
    var db = "no";
    wx.getUserInfo({
      success: function (res) {
        that.data.nickName = res.userInfo.nickName,
          that.data.avatarUrl = res.userInfo.avatarUrl,
          that.setData({
            nickName: that.data.nickName,
            avatarUrl: that.data.avatarUrl,
          })
      },
      fail: function (res) {
        that.data.nickName = "未授权无法获取用户信息",
          that.setData({
            nickName: that.data.nickName
          })
      }
    })
  },

  onShow(){
    const userinfo=wx.getStorageSync("userinfo");
    const collect=wx.getStorageSync("collect")||[]; 
    this.setData({
      userinfo,
      collectNums:collect.length
    });
  }
})